package com.afc.struts.bustle.product;

import java.util.Date;
import java.util.List;
import java.util.Vector;

import com.afc.struts.annotations.PossibleValues;
import com.afc.struts.bustle.data.ProviderDao;
import com.afc.struts.bustle.model.ProductDto.ProductType;
import com.afc.struts.bustle.model.ProviderDto;
import com.afc.struts.form.ActionForm;
import com.afc.struts.utils.LabeledBoolean;
import com.afc.struts.utils.StringUtils;

public interface ProductForm extends ActionForm
{
  public int getId();
  public void setId(int aId);

  public ProductType getType();
  public void setType(ProductType aType);

  public String getName();
  public void setName(String aName);

  public double getPrice();
  public void setPrice(double aPrice);

  public String getDescription();
  public void setDescription(String aDescription);

  public Date getCreationDate();
  public void setCreationDate(Date aCreationDate);

  public Date getLimitedDate();
  public void setLimitedDate(Date aLimitedDate);

  public String getImage();
  public void setImage(String aImage);

  @PossibleValues("getPossibleBestFriends")
  public ProviderDto getProvider();
  public void setProvider(ProviderDto aBestFriend);
  public List<ProviderDto> getPossibleProviders();

  public class DefaultProductForm implements ProductForm
  {
    public DefaultProductForm()
    {
      possibleProviders = new Vector<>();
      possibleProviders.add(null);
      possibleProviders.addAll(ProviderDao.getInstance().retrieveAll());
    }

    public DefaultProductForm(int aId, ProductType aType, String aName, double aPrice, String aDescription, Date aCreationDate, Date aLimitedDate, String aImage, ProviderDto aProvider)
    {
      this();
      id = aId;
      type = aType;
      name = aName;
      price = aPrice;
      description = aDescription;
      creationDate = aCreationDate;
      limitedDate = aLimitedDate;
      image = aImage;
      provider = aProvider;
    }

    @Override
    public int getId()
    {
      return id;
    }

    @Override
    public void setId(int aId)
    {
      id = aId;
    }

    @Override
    public ProductType getType()
    {
      return type;
    }

    @Override
    public void setType(ProductType aType)
    {
      type = aType;
    }

    @Override
    public String getName()
    {
      return name;
    }

    @Override
    public void setName(String aName)
    {
      name = aName;
    }

    @Override
    public double getPrice()
    {
      return price;
    }

    @Override
    public void setPrice(double aPrice)
    {
      price = aPrice;
    }

    @Override
    public String getDescription()
    {
      return description;
    }

    @Override
    public void setDescription(String aDescription)
    {
      description = aDescription;
    }

    @Override
    public Date getCreationDate()
    {
      return creationDate;
    }

    @Override
    public void setCreationDate(Date aCreationDate)
    {
      creationDate = aCreationDate;
    }

    @Override
    public Date getLimitedDate()
    {
      return limitedDate;
    }

    @Override
    public void setLimitedDate(Date aLimitedDate)
    {
      limitedDate = aLimitedDate;
    }

    @Override
    public String getImage()
    {
      return image;
    }

    @Override
    public void setImage(String aImage)
    {
      image = aImage;
    }

    @Override
    @PossibleValues("getPossibleProviders")
    public ProviderDto getProvider()
    {
      return provider;
    }

    @Override
    public void setProvider(ProviderDto aProvider)
    {
      provider = aProvider;
    }

    @Override
    public List<ProviderDto> getPossibleProviders()
    {
      return possibleProviders;
    }

    @Override
    public LabeledBoolean validateForm()
    {
      LabeledBoolean validate = LabeledBoolean.check(StringUtils.isFeed(name), "Product must have a name");
      if (validate.isTrue())
      {
        validate = LabeledBoolean.check(provider != null, "Product must have a provider");
      }
      return validate;
    }

    private int id;
    private ProductType type;
    private String name;
    private double price;
    private String description;
    private Date creationDate;
    private Date limitedDate;
    private String image;
    private ProviderDto provider;
    private final List<ProviderDto> possibleProviders;
  }
}
